﻿using UnityEngine;
using System.Collections;

public class EndPosCheck : MonoBehaviour {

    private bool isArrive = false;

    void Update()
    {
        if (isArrive)
        {
            transform.localScale = transform.localScale * 0.995f;
            if (transform.localScale.sqrMagnitude < 0.05f)
            {
                Application.LoadLevel(Application.loadedLevel);
            }
        }
    }

    public void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Player" && isArrive == false)
        {
            isArrive = true;
            TimeControl tc = GameObject.Find("Canvas").GetComponent<TimeControl>();
            float time = tc.Timer;
            float highscore = PlayerPrefs.GetFloat("HighScore");
            if (highscore == 0 || highscore > time)
                PlayerPrefs.SetFloat("HighScore", time);
            tc.enabled = false;
        }
    }
}
